//
//  ImageUploadUtil.m
//  deerkids
//
//  Created by 王昭的Mac Air on 2017/10/19.
//  Copyright © 2017年 wangzhao. All rights reserved.
//

#import "ImageUploadUtil.h"


@implementation ImageUploadUtil

+(void)uploadImage:(NSData *) data api:(NSString *)api param:(NSDictionary *)params callback:(void (^)(NSString *imageurl,NSDictionary *videoDict,NSString *message))callback{
    [NetworkUtil uploadPost:api parameters:params file:data success:^(id responseObject) {
        NSDictionary *dict = responseObject;
        if(dict && callback){
            callback(dict[@"data"][@"image_id"],dict[@"data"],@"");
        }else{
            if(callback){
                callback(@"",nil,@"");
            }
        }
        
    } failure:^(NSError *error, NSString *message) {
        if(callback){
            callback(@"",nil,message);
        }
    }];
}
+(void)uploadImage:(NSData *)data param:(NSDictionary *)params callback:(void (^)(NSString *, NSDictionary *, NSString *))callback{
    [NetworkUtil uploadPost:API_UploadWallpaper parameters:params file:data success:^(id responseObject) {
        NSDictionary *dict = responseObject;
        if(dict && callback){
            callback(dict[@"data"][@"image_id"],dict[@"data"],@"");
        }else{
            if(callback){
                callback(@"",nil,@"");
            }
        }
        
    } failure:^(NSError *error, NSString *message) {
        if(callback){
            callback(@"",nil,message);
        }
    }];
}

+(void)updateImage:(NSData *) path type:(NSString *)nav_type callback:(void (^)(NSString *imageurl,NSDictionary *videoDict,NSString *message))callback{
    [NetworkUtil uploadPost:API_UploadImage(nav_type) parameters:@{@"session_uid":[UserUtil getUser].user_id} file:path success:^(id responseObject) {
        NSDictionary *dict = responseObject;
        if(dict && callback){
            callback(dict[@"data"][@"image_id"],dict[@"data"],@"");
        }else{
            if(callback){
                callback(@"",nil,@"");
            }
        }
        
    } failure:^(NSError *error, NSString *message) {
        if(callback){
            callback(@"",nil,message);
        }
    }];
}


//+ (NSString *)requireOjectKey:(OssUploadType)type path:(NSString *)path
//{
//    //获取图片
//    NSArray *arr = @[@"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", @"i", @"j", @"k", @"l", @"m", @"n", @"o", @"p", @"q", @"r", @"s", @"t", @"u", @"v", @"w", @"x", @"y", @"z", @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"];
//    NSMutableString *muStr = [[NSMutableString alloc] init];
//    while ([muStr length] < 8) {
//        int r = arc4random() % [arr count];
//        [muStr appendString:arr[r]];
//    }
//    if (type == OssUploadTypeImage) {
//        [muStr appendString:@".jpg"];
//    }else{
//        [muStr appendString:@".mp4"];
//    }
//    return [path stringByAppendingPathComponent:muStr];
//}


@end
